var insert_product_item = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"T1", "MSG":"","DATA":"","SCRIPTNAME":"insert_product_item"}');
var relation_item_list_info_json = isNull(relation_item_list_info) ? [] : JSON.parse(relation_item_list_info);
var relation_item_list_json = isNull(relation_item_list) ? [] : relation_item_list.split(",");
// var item_store_json_list = isNull(item_store_json) ? [] : JSON.parse(item_store_json);
// if (!isNull(item_store_json_list)) {
//
// }

//自增一品多号
function difference(array1, array2) {
    // 创建一个对象来存储array2中的元素
    var lookup = {};
    array2.forEach(function (item) {
        lookup[item] = true;
    });

    // 使用filter方法，并检查元素是否在lookup对象中
    return array1.filter(function (item) {
        return !lookup[item];
    });
}

var addMapPrice = new Map();
var addMapCost = new Map();
var addMapStatus = new Map();
var addMapQty = new Map();
var addMapTax = new Map();


//一品多号
if (!isNull(relation_item_list_info_json)) {
    for (var rili1 = 0; rili1 < relation_item_list_info_json.length; rili1++) {
        var listInfoJsonElement = relation_item_list_info_json[rili1];
        var relationItemNbr = listInfoJsonElement.item_nbr;
        if (relationItemNbr !== item_nbr) {
            if (!isNull(retail_tax)) {
                var addPriceObj = {
                    source: 19,
                    biz_type: biz_type,
                    biz_scope: biz_scope,
                    change_type: change_type,
                    channel_id: channel_id,
                    price_change_request_id: price_change_request_id,
                    store_type: store_type,
                    process_status: 1000,
                    create_by: 'system',
                    update_by: 'system',
                    // category_nbr: listElement.category_nbr,

                    retail_tax: retail_tax,
                    retail: retail,
                    retail_comment: retail_comment,
                    retail_change_type: retail_change_type,
                    retail_start_date: retail_start_date,
                    retail_end_date: retail_end_date,
                    send_va_flag: 0,
                    active_discount: 1
                }
                if (!isNull(store_id)) {
                    addPriceObj.store_id = store_id;
                } else if (!isNull(trait_nbr) && trait_nbr === 'ALL') {
                    addPriceObj.trait_nbr = 'ALL';
                } else if (!isNull(trait_nbr)) {
                    addPriceObj.trait_nbr = trait_nbr;
                }
                addPriceObj.item_nbr = relationItemNbr;
                addMapPrice.put(relationItemNbr, addPriceObj);
            }

            //状态
            if (!isNull(item_status)) {
                //TODO:波哥写
                var itemSdj = JSON.parse(listInfoJsonElement.item_store_dc_json);
                var addStatusObj = {
                    source: 19,
                    biz_type: biz_type,
                    biz_scope: biz_scope,
                    change_type: change_type,
                    channel_id: channel_id,
                    price_change_request_id: price_change_request_id,
                    store_type: store_type,
                    process_status: 1000,
                    create_by: 'system',
                    update_by: 'system',
                    item_status: item_status
                }
                addStatusObj.item_nbr = relationItemNbr;
                // 一品多号对应的发送门店
                var storeSdj = getUniqueValues(itemSdj, "store_id");

                if (!isNull(trait_nbr) && trait_nbr !== 'ALL') {
                    var resSpList = relation_store.split(",");
                    var addRelationStore = resSpList.filter(function (value) {
                        return storeSdj.indexOf(value) !== -1;
                    });
                    if (!isNull(addRelationStore)) {
                        for (var ars1 = 0; ars1 < addRelationStore.length; ars1++) {
                            addStatusObj.store_id = addRelationStore[ars1];
                            if (addMapStatus.containsKey(relationItemNbr)) {
                                var amsList1 = addMapStatus.get(relationItemNbr);
                                amsList1.push(addStatusObj);
                            } else {
                                addMapStatus.put(relationItemNbr, [addStatusObj]);
                            }
                        }
                    }

                } else if (!isNull(trait_nbr) && trait_nbr === 'ALL') {
                    for (var so1 = 0; so1 < storeSdj.length; so1++) {
                        addStatusObj.store_id = storeSdj[so1];
                        if (addMapStatus.containsKey(relationItemNbr)) {
                            var amsList = addMapStatus.get(relationItemNbr);
                            amsList.push(addStatusObj);
                        } else {
                            addMapStatus.put(relationItemNbr, [addStatusObj]);
                        }
                    }
                } else if (!isNull(store_id)) {
                    addStatusObj.store_id = store_id;
                    if (addMapStatus.containsKey(relationItemNbr)) {
                        var amsList2 = addMapStatus.get(relationItemNbr);
                        amsList2.push(addStatusObj);
                    } else {
                        addMapStatus.put(relationItemNbr, [addStatusObj]);
                    }
                }

            }
            //税率
            if (!isNull(tax_rate)) {
                var addTaxRateObj = {
                    source: 19,
                    biz_type: biz_type,
                    biz_scope: biz_scope,
                    change_type: change_type,
                    channel_id: channel_id,
                    price_change_request_id: price_change_request_id,
                    store_type: store_type,
                    process_status: 1000,
                    create_by: 'system',
                    update_by: 'system',

                    tax_rate: tax_rate
                }
                //一品多号
                if (!isNull(relation_item_list)) {

                }
            }
        }
    }
}

//成本
if (!isNull(cost)) {
    var addCostObj = {
        source: 19,
        biz_type: biz_type,
        biz_scope: biz_scope,
        change_type: change_type,
        channel_id: channel_id,
        price_change_request_id: price_change_request_id,
        store_type: store_type,
        process_status: 1000,
        create_by: 'system',
        update_by: 'system',
        // category_nbr: listElement.category_nbr,

        cost_tax: cost_tax,
        cost: retail,
        cost_comment: cost_comment,
        cost_change_type: cost_change_type,
        cost_applicable_cargo_volume: cost_applicable_cargo_volume,
        cost_start_date: cost_start_date,
        cost_end_date: cost_end_date,
        send_va_flag: 0,
        active_discount: 1
    }
}
//箱规
if (!isNull(vnpk_qty)) {
    var addQtyObj = {
        source: source,
        biz_type: biz_type,
        biz_scope: biz_scope,
        change_type: change_type,
        channel_id: channel_id,
        price_change_request_id: price_change_request_id,
        store_type: store_type,
        process_status: 1000,
        create_by: 'system',
        update_by: 'system',

        vnpk_qty: vnpk_qty
    }
}


//如果
// var difference1 = difference(relationList,itemNbrList);
//有一品多好数据
// var relationObj = relationMap.get(curItem);
//如果已添加价格税率状态，则跳过
// if (!isNull(relationObj)) {
//     //如果有一品多号，并且有未提交的一品多号item，则新增本条item对应的数据
//     var filterRelation = relationObj.filter(function (value) {
//         return parseInt(value) !== parseInt(curItem)
//             && itemNbrList.indexOf(value) === -1
//     });

//     if (!isNull(retail_tax)) {
//         var addPriceObj = {
//             source: source,
//             biz_type: biz_type,
//             biz_scope: biz_scope,
//             change_type: change_type,
//             channel_id: channel_id,
//             price_change_request_id: price_change_request_id,
//             store_type: store_type,
//             process_status: 1000,
//             create_by: 'system',
//             update_by: 'system',
//             // category_nbr: category_nbr,
//
//             retail_tax: retail_tax,
//             retail: retail,
//             retail_comment: retail_comment,
//             retail_change_type: retail_change_type,
//             retail_start_date: retail_start_date,
//             retail_end_date: retail_end_date,
//             send_va_flag: 0,
//             active_discount: 1
//         }
//         if (!isNull(listElement.store_id)) {
//             addPriceObj.store_id = listElement.store_id;
//         } else if (!isNull(listElement.trait_nbr) && listElement.trait_nbr === 'ALL') {
//             addPriceObj.trait_nbr = 'ALL';
//         } else if (!isNull(listElement.trait_nbr)) {
//             addPriceObj.trait_nbr = listElement.trait_nbr;
//         }
//         //一品多号
//         if (!isNull(filterRelation)) {
//             for (var ifR1 = 0; ifR1 < filterRelation.length; ifR1++) {
//                 var addItem = filterRelation[ifR1];
//                 addPriceObj.item_nbr = addItem;
//                 addMapPrice.put(addItem, addPriceObj);
//             }
//         }
//
//     }
//     //成本
//     if (!isNull(cost)) {
//         var addCostObj = {
//             source: source,
//             biz_type: biz_type,
//             biz_scope: biz_scope,
//             change_type: change_type,
//             channel_id: channel_id,
//             price_change_request_id: price_change_request_id,
//             store_type: store_type,
//             process_status: 1000,
//             create_by: 'system',
//             update_by: 'system',
//             // category_nbr: listElement.category_nbr,
//
//             cost_tax: cost_tax,
//             cost: retail,
//             cost_comment: cost_comment,
//             cost_change_type: cost_change_type,
//             cost_applicable_cargo_volume: cost_applicable_cargo_volume,
//             cost_start_date: cost_start_date,
//             cost_end_date: cost_end_date,
//             send_va_flag: 0,
//             active_discount: 1
//         }
//     }
//     //状态
//     if (!isNull(item_status)) {
//         var addStatusObj = {
//             source: source,
//             biz_type: biz_type,
//             biz_scope: biz_scope,
//             change_type: change_type,
//             channel_id: channel_id,
//             price_change_request_id: price_change_request_id,
//             store_type: store_type,
//             process_status: 1000,
//             create_by: 'system',
//             update_by: 'system',
//
//             item_status: item_status
//         }
//     }
//     //箱规
//     if (!isNull(vnpk_qty)) {
//         var addQtyObj = {
//             source: source,
//             biz_type: biz_type,
//             biz_scope: biz_scope,
//             change_type: change_type,
//             channel_id: channel_id,
//             price_change_request_id: price_change_request_id,
//             store_type: store_type,
//             process_status: 1000,
//             create_by: 'system',
//             update_by: 'system',
//
//             vnpk_qty: vnpk_qty
//         }
//     }
//     if (!isNull(tax_rate)) {
//         var addTaxRateObj = {
//             source: source,
//             biz_type: biz_type,
//             biz_scope: biz_scope,
//             change_type: change_type,
//             channel_id: channel_id,
//             price_change_request_id: price_change_request_id,
//             store_type: store_type,
//             process_status: 1000,
//             create_by: 'system',
//             update_by: 'system',
//
//             tax_rate: tax_rate
//         }
//         //一品多号
//         if (!isNull(filterRelation)) {
//             for (var ifR5 = 0; ifR5 < filterRelation.length; ifR5++) {
//                 var addItemTaxRate = filterRelation[ifR5];
//                 addItemTaxRate.item_nbr = addItemTaxRate;
//                 addItemTaxRate.trait_nbr = 'ALL'
//                 addMapPrice.put(addItemTaxRate, addTaxRateObj);
//             }
//         }
//     // }
// }

// var updateData = [];
//
// var updateDataRequestSku = {
//     tableName: 'price_change_request_sku',
//     data: []
// };
//
// var skuItem = {
//     retail_tax: 144,
//     biz_type: 2,
//     biz_scope: 1,
//     change_type: 1,
//     channel_id: '2',
//     create_by: 'system',
//     update_by: 'system',
//     price_change_request_id: price_change_request_id
// }
//
// updateDataRequestSku.data.push(skuItem);
// updateData.push(updateDataRequestSku);
//
// baseMsg.CODE = 3;
// baseMsg.ACTION = 'insert ';
// baseMsg.MSG = '插入价格当前价格为100 单号：' + price_change_request_id + ' 来自 ID：' + id;
// baseMsg.DATA = JSON.stringify(updateData);

JSON.stringify(insert_product_item);
